<?php

namespace Frieza\Modules\Course\Controllers;

use App\Http\Controllers\Controller;
use App\Pockets\GridDataModel as pGridDataModel;
use Biz\cache\course\WhiteUser;
use Biz\model\course\Chapter as mChapter;
use Biz\model\course\Course as mCourse;
use Biz\service\course\AdmCourse;
use Doraemon\tools\Log;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Form;
use Encore\Admin\Widgets\Tab;
use Illuminate\Http\Request;
use Illuminate\Support\MessageBag;

class IndexController extends Controller
{
    const PAGE_SIZE = 20;

    public function __construct()
    {
        parent::__construct();
        Admin::script('$(".pjax-container").attr("id","pjax-container");');
    }

    public function index(Request $request, Content $content)
    {
        $pageSize = $request->input("per_page", 20);
        $page = $request->input("page", 1);
        $condition = $this->_index_condition($request);
        $where = $condition;
        $where['LIMIT'] = [
            ($page - 1) * $pageSize,
            $pageSize
        ];
        $result = AdmCourse::getCourseList($where);
        $gridModel = new pGridDataModel($result['list'], $result['total'], [
            'perPage' => $pageSize
        ]);
        Admin::script($this->offlineScript());
        Admin::script($this->onlineScript());
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) use ($gridModel) {
                $grid->paginate($gridModel->getPerPage());
                $grid->filter(function (Grid\Filter $filter) {
                    // 去掉默认的id过滤器
                    $filter->disableIdFilter();
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('course_id', '课程id');
                        $filter->equal('course_status', '课程状态')->select(mCourse::STATUS_DESC);
                    });
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('title', '标题');
                    });
                    if (!empty($condition)) {
                        $filter->expand();//默认展开
                    }
                });
                $grid->disableExport();
                $grid->disableRowSelector();
                $grid->column('id', '课程id');
                $grid->column('title', '标题');
                $grid->column('desc', '描述');
                $grid->column('spec_img', '课程主图')->image($this->spec_img, 100, 100);
                $grid->column('duration', '视频时长');
                $grid->column('chapter_num', '章节数量');
                $grid->column('is_try', '支持试看')->display(function () {
                    return $this->is_try ? '是' : '否';
                });
                $grid->column('is_show', '显示/隐藏')->display(function () {
                    return $this->is_show ? '显示' : '隐藏';
                });
                $grid->column('is_free', '是否免费')->display(function () {
                    return $this->is_free ? '免费' : '否';
                });
                $grid->column('course_tag', '课程标签');
                $grid->column('status_desc', '状态');
                $grid->column('price', '课程价格');
                //$grid->column('apple_gid', '苹果商品id');
                $grid->column('addtime', '添加时间');
                $grid->column('edittime', '编辑时间');
                $grid->actions(function (Grid\Displayers\Actions $actions) {
                    $actions->disableDelete();
                    if ($actions->row->course_status == mCourse::STATUS_OFFLINE) {
                        $actions->prepend('&nbsp;<a class="fa online-data" data-id="' . $actions->row->id . '" href="javascript:void(0);">上架</a>');
                    } else if ($actions->row->course_status == mCourse::STATUS_ONLINE) {
                        $actions->prepend('&nbsp;<a class="fa" href="' . url('admin/course/index/') . '/' . $actions->row->id . '/white' . '">白名单</a>');
                        $actions->prepend('&nbsp;<a class="fa offline-data" data-id="' . $actions->row->id . '" href="javascript:void(0);">下架</a>');
                    }
                    $actions->prepend('<a class="fa fa-envelope" href="javascript:layer.open({
                                type: 2,
                                title: \'预览\',
                                maxmin: true,
                                area: [\'800px\', \'500px\'],
                                content: \'' . $actions->row->h5_url . '\'
                            });">预览</a>');
                });
            }
        );
        $tab = new Tab();
        $tab->add('课程列表', $gridList->render(), true);
        $tab->addLink('精品课程', url('/admin/course/recommend'), false);
        return $content->header('课程列表')->breadcrumb(
            ['text' => '课程列表'])
            ->row($tab);
    }

    public function recommend(Request $request, Content $content)
    {
        $list = AdmCourse::getRecommend();
        $gridModel = new pGridDataModel($list);
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) use ($gridModel) {
                $grid->disableFilter();
                $grid->disableCreateButton();
                $grid->disableActions();
                $grid->disablePagination();
                $grid->disableExport();
                $grid->disableRowSelector();
                $grid->column('id', '课程id')->sort();
                $grid->column('title', '标题');
                $grid->column('desc', '描述');
                $grid->column('spec_img', '课程主图')->image($this->spec_img, 100, 100);
                $grid->column('duration', '视频时长');
                $grid->column('chapter_num', '章节数量');
                $grid->column('status_desc', '状态');
                $grid->column('price', '课程价格');
                $grid->column('apple_gid', '苹果商品id');
                $grid->column('addtime', '添加时间');
                $grid->column('edittime', '编辑时间');
            }
        );
        $tab = new Tab();
        $tab->addLink('课程列表', url('/admin/course/index'), false);
        $tab->add('精品课程', $gridList->render(), true);
        return $content->header('精品课程')->breadcrumb(
            ['text' => '精品课程'])
            ->row($tab);
    }

    public function sort(Request $request)
    {
        $sortInfo = $request->input('sort');
        foreach ($sortInfo as $id => $sort) {
            AdmCourse::sort($sort, $id);
        }
    }

    public function offline(Request $request)
    {
        try {
            $courseId = $request->input('id', 0);
            if ($courseId) {
                $result = AdmCourse::offlineCourse($courseId, Admin::user()->id);
                $success = [
                    'title' => '课程 ID: ' . $courseId . ' 下架成功',
                    'code' => 1
                ];
            }
        } catch (\Exception $e) {
            $success = [
                'title' => '下架失败' . $e->getMessage(),
                'msg' => '信息：' . $e->getFile() . $e->getLine(),
                'code' => 0,
                'status' => false,
            ];
        }
        return response()->json($success);
    }

    public function delChapter(Request $request, $courseId, $chapterId)
    {
        try {
            $adminId = Admin::user()->id;
            $result = AdmCourse::delChapter($courseId, $chapterId, Admin::user()->id);
            return response()->json([
                'status' => true,
                'message' => "操作成功",
            ]);
        } catch (\Exception $e) {
            return response()->json([
                'status' => false,
                'message' => "操作失败",
            ]);
        }
        return response()->json($success);
    }

    public function online(Request $request)
    {
        try {
            $adminId = Admin::user()->id;
            $courseId = $request->input('id', 0);
            if ($courseId) {
                $result = AdmCourse::onlineCourse($courseId, $adminId);
                $success = [
                    'title' => '课程 ID: ' . $courseId . ' 上架成功',
                    'code' => 1
                ];
            }
        } catch (\Exception $e) {
            $success = [
                'title' => '上架失败,' . $e->getMessage(),
                'msg' => '信息：' . $e->getFile() . $e->getLine(),
                'code' => 0,
                'status' => false,
            ];
        }
        return response()->json($success);
    }

    private function offlineScript()
    {
        return <<<SCRIPT
        $('.offline-data').unbind('click').click(function(){
            var id= $(this).data('id');
            if(confirm('确定要下架该课程:'+id+'吗？')){
                let url = 'offline'
                let params = {id:id}
                $.post(url, params , function (result) {
                    if (result.code == 1) {
                        layer.msg(result.title);
                        setTimeout(function () {
                            parent.window.location.reload();
                        }, 2000);
                    } else {
                        layer.msg(result.title);
                    }
                });
            }
        });
SCRIPT;
    }

    private function onlineScript()
    {
        return <<<SCRIPT
        $('.online-data').unbind('click').click(function(){
            var id= $(this).data('id');
            if(confirm('确定要上架架该课程:'+id+'吗？')){
                let url = 'online'
                let params = {id:id}
                $.post(url, params , function (result) {
                    if (result.code == 1) {
                        layer.msg(result.title);
                        setTimeout(function () {
                            parent.window.location.reload();
                        }, 2000);
                    } else {
                        layer.msg(result.title);
                    }
                });
            }
        });
SCRIPT;
    }

    public function create(Request $request, Content $content, $id = 0)
    {
        $tabId = $request->input('tab', 0);
        $header = '添加课程';
        if ($id) {
            $header = '编辑课程';
        }
        $url = $id ? url('/admin/course/index/') . '/' . $id . '/edit' : url('/admin/course/create');
        $tab = new Tab();
        if ($tabId == 0) {
            $row = $this->tabCourse($id);
            $tab->add('课程', $row, true);
            if ($id) {
                $tab->addLink('章节', $url . '?tab=1');
            }
        } else {
            $row = $this->tabChapter($id);
            $tab->addLink('课程', $url, false);
            $tab->add('章节', $row, true);
        }
        return $content->header($header)->breadcrumb(
            ['text' => '课程列表', 'url' => url('admin/course/index')],
            ['text' => $header])
            ->row($tab);
    }

    private function tabCourse($id)
    {
        $tags = explode( "\n",file_get_contents('/home/adm_rsync_dir/tags/adm_tags_all'));
        if($tags && is_array($tags)){
            $tags = array_combine($tags , $tags);
        }
        $info = $id ? AdmCourse::getCourseInfo($id) : [];
        $form = new Form($info);
        $form->hidden('course_id');
        $form->text('title', '课程标题')->required()->help('最多输入15个字')->attribute('maxlength', '15');
        $form->text('desc', '课程描述')->required()->help('最多输入20个字')->attribute('maxlength', '20');
        $form->text('teacher_name', '讲师姓名')->help('最多输入15个字')->attribute('maxlength', '15')->required();
        $form->text('teacher_uid', '讲师uid');
        $form->imgUpload('spec_img', '课程主图')->help('单图，必须需要上传');
        $form->imgUpload('teacher_img', '讲师图像')->help('单图，必须需要上传');
        $form->currency('original_price', '课程原价')->help('单位元');
        $form->currency('price', '课程价格')->required()->help('单位元');
        //$form->text('apple_gid', '苹果对应商品Id')->help('苹果后台配置的商品id');
        $form->radio('is_show', '显示/隐藏')->options([1 => '显示',0 => '隐藏'])->default(1);
        $form->radio('is_free', '是否免费')->options([0 => '不免费',1 => '免费'])->default(0);
        $form->multipleSelect("course_tag", '标签')->options($tags);

        $form->text('share_title', '分享标题');
        $form->text('share_desc', '分享描述');
        $form->imgUpload('share_img', '分享图')->help('单图');
        $form->imgUpload('content', '课程详情', 1)->help('多图，编辑时候可以拖拽图片排序。');
        $form->textarea('receive_link', '领取课件链接');
        $form->text('receive_pwd', '领取课件密码');
        $form->action(url('admin/course/save'));
        return $form->render();
    }

    private function tabChapter($id)
    {
        return $this->chapterForm($id) . $this->chapterGrid($id);
    }

    private function chapterGrid($courseId = 0)
    {
        $list = AdmCourse::getChapterList($courseId);
        $gridModel = new pGridDataModel($list);
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) {
                $grid->disableFilter();
                $grid->disableExport();
                $grid->disableRowSelector();
                $grid->disableCreateButton();
                $grid->column('id', '章节id');
                $grid->column('course_id', '课程id');
                $grid->column('name', '章节名称');
                $grid->column('is_try', '支持试看')->display(function () {
                    return $this->is_try ? '是' : '否';
                });
                $grid->column('pic_url', '视频预览图')->image($this->pic_url, 100, 100);
                $grid->column('duration', '时长');
                $grid->column('sort', '排序');
                $grid->column('addtime', '添加时间');
                $grid->column('edittime', '编辑时间');

                $grid->actions(function (Grid\Displayers\Actions $actions) {
                    if ($actions->row->chapter_status != mChapter::STATUS_NORMAL) {
                        $actions->disableDelete();
                    }
                });
            }
        );
        return $gridList->render();
    }

    public function evaluation(Request $request, Content $content)
    {
        $tabNum = $request->input('tab', 0);
        $tab = new Tab();
        if (!$tabNum) {
            $gridList = self::getAllEvaluationGrid($request);
            $tab->add('全部评价列表', $gridList->render(), true);
            $tab->addLink('课程评分', url('/admin/course/evaluation') . '?tab=1', false);
        } else {
            $gridList = self::getCourseEvaluationGrid($request);
            $tab->addLink('全部评价列表', url('/admin/course/evaluation'), false);
            $tab->add('课程评分', $gridList->render(), true);
        }
        return $content->header('课程评价')->breadcrumb(
            ['text' => '课程评价'])
            ->row($tab);
    }

    private function getAllEvaluationGrid($request)
    {
        $pageSize = $request->input("per_page", 20);
        $page = $request->input("page", 1);
        if (isset($request['course_id']) && ($request['course_id'] > 0)) {
            $where['course_id'] = $request['course_id'];
        } elseif (isset($request['title']) && strlen($request['title']) > 0) {
            $courseIds = mCourse::selectByWhere(['title[~]' => $request['title']], 'course_id');
            $where['course_id'] = $courseIds;
        }
        $where['LIMIT'] = [
            ($page - 1) * $pageSize,
            $pageSize
        ];
        $where['ORDER'] = [
            'id' => 'DESC'
        ];
        $result = AdmCourse::getEvaluationList($where);
        $gridModel = new pGridDataModel($result['list'], $result['total'], [
            'perPage' => $pageSize
        ]);
        Admin::script($this->offlineScript());
        Admin::script($this->onlineScript());
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) use ($gridModel) {
                $grid->paginate($gridModel->getPerPage());
                $grid->disableCreateButton();
                $grid->filter(function (Grid\Filter $filter) {
                    // 去掉默认的id过滤器
                    $filter->disableIdFilter();
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('course_id', '课程id');
                    });
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('title', '标题');
                    });
                    if (!empty($condition)) {
                        $filter->expand();//默认展开
                    }
                });
                $grid->disableExport();
                $grid->disableRowSelector();
                $grid->column('id', 'id');
                $grid->column('course_id', '课程id');
                $grid->column('course_title', '标题');
                $grid->column('uid', '评价用户')->display(function () {
                    return '<p>' . $this->uid . '</p>' . '<p>' . $this->nick . '</p>';
                });
                $grid->column('course_start', '课程满意度')->display(function () {
                    $html = "<i class='fa fa-star' style='color:#ff8913'></i>";
                    if ($this->course_start < 1) {
                        return '';
                    }
                    return join('&nbsp;', array_fill(0, min(5, $this->course_start), $html));
                });
                $grid->column('teacher_start', '讲师满意度')->display(function () {
                    $html = "<i class='fa fa-star' style='color:#ff8913'></i>";
                    if ($this->teacher_start < 1) {
                        return '';
                    }
                    return join('&nbsp;', array_fill(0, min(5, $this->teacher_start), $html));
                });
                $grid->column('ue_start', '功能及体验')->display(function () {
                    $html = "<i class='fa fa-star' style='color:#ff8913'></i>";
                    if ($this->ue_start < 1) {
                        return '';
                    }
                    return join('&nbsp;', array_fill(0, min(5, $this->ue_start), $html));
                });
                $grid->column('content', '评价详情');
                $grid->column('addtime', '评价时间');
                $grid->disableActions();
            }
        );
        return $gridList;
    }

    private function getCourseEvaluationGrid($request)
    {
        $pageSize = $request->input("per_page", 20);
        $page = $request->input("page", 1);
        if (isset($request['course_id']) && ($request['course_id'] > 0)) {
            $where['course_id'] = $request['course_id'];
        } elseif (isset($request['title']) && strlen($request['title']) > 0) {
            $where['title[~]'] = $request['title'];
        }
        $where['LIMIT'] = [
            ($page - 1) * $pageSize,
            $pageSize
        ];
        $result = AdmCourse::getCourseEvaluation($where);
        $gridModel = new pGridDataModel($result['list'], $result['total'], [
            'perPage' => $pageSize
        ]);
        Admin::script($this->offlineScript());
        Admin::script($this->onlineScript());
        $gridList = Admin::grid($gridModel,
            function (Grid $grid) use ($gridModel) {
                $grid->disableCreateButton();
                $grid->paginate($gridModel->getPerPage());
                $grid->filter(function (Grid\Filter $filter) {
                    // 去掉默认的id过滤器
                    $filter->disableIdFilter();
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('course_id', '课程id');
                    });
                    $filter->column(1 / 2, function ($filter) {
                        $filter->equal('title', '标题');
                    });
                    if (!empty($condition)) {
                        $filter->expand();//默认展开
                    }
                });
                $grid->disableExport();
                $grid->disableRowSelector();
                $grid->column('id', 'id');
                $grid->column('course_id', '课程id');
                $grid->column('title', '标题');
                $grid->column('course_start', '课程满意度平均分')->display(function () {
                    return $this->course_start . '分';
                });
                $grid->column('teacher_start', '讲师满意度平均分')->display(function () {
                    return $this->teacher_start . '分';
                });
                $grid->column('ue_start', '功能及体验平均分')->display(function () {
                    return $this->ue_start . '分';
                });
                $grid->disableActions();
            }
        );
        return $gridList;
    }

    private function chapterForm($courseId = 0, $chapterId = 0)
    {
        $info = [];
        if ($chapterId) {
            $info = AdmCourse::getChapterInfo($chapterId);
        }
        $info['course_id'] = $courseId;
        $info['id'] = $chapterId;
        $form = new Form($info);
        $form->hidden('course_id');
        $form->hidden('id');
        $form->text('name', '标题')->help('最多输入20个字')->attribute('maxlength', '20');
        $form->radio('is_try', '支持试看')->options([0 => '否', 1 => '是'])->default(0);
        $form->videoUpload('video_id', '视频', 'course')->help('请注意，视频上传成功后再保存。视频最大不能超过100M。');
        $form->text('sort', '章节顺序')->default(0)->help('章节顺序，升序排列。如果未设置，按id正序排列。');
        $form->action(url('admin/course/saveChapter'));
        return $form->render();
    }


    public function save(Request $request)
    {
        try {
            $params = $request->all();
            $id = isset($params['course_id']) ? $params['course_id'] : 0;
            $course_tag_arr = array_unique(array_filter($request['course_tag'])) ?: [];
            $course_tag = '';
            if ($course_tag_arr && is_array($course_tag_arr)) {
                $course_tag = implode(",", $course_tag_arr);
            }
            $data = [
                'teacher_uid' => (isset($params['teacher_uid']) && $params['teacher_uid']) ? $params['teacher_uid'] : 0,
                'teacher_name' => $params['teacher_name'],
                'title' => $params['title'],
                'desc' => $params['desc'],
                'spec_img' => $params['spec_img'],
                'teacher_img' => $params['teacher_img'],
                'original_price' => $params['original_price'] ? $params['original_price'] : 0,
                'price' => $params['price'] ? $params['price'] : 0,
                'share_title' => $params['share_title'] ? $params['share_title'] : '',
                'share_desc' => $params['share_desc'] ? $params['share_desc'] : '',
                'share_img' => $params['share_img'] ? $params['share_img'] : '',
                //'apple_gid' => (isset($params['apple_gid']) && $params['apple_gid']) ? $params['apple_gid'] : 0,
                'is_show'=> isset($params['is_show']) ? $params['is_show'] : 1,
                'is_free'=> isset($params['is_free']) ? $params['is_free'] : 0,
                'course_tag' => $course_tag,
                'content' => $params['content'],
                'receive_link' => json_encode(['link' => !empty($params['receive_link']) ? $params['receive_link'] : '', 'pwd' => !empty($params['receive_pwd']) ? $params['receive_pwd'] : ''], JSON_UNESCAPED_UNICODE)
            ];
            if (empty($data['spec_img'])) {
                throw new \Exception('必须上传主图');
            }
            if (empty($data['teacher_img'])) {
                throw new \Exception('必须上传讲师图像');
            }
            if (empty($data['title'])) {
                throw new \Exception('必须设置课程标题');
            }
            if (empty($data['desc'])) {
                throw new \Exception('必须设置课程描述');
            }
            $result = AdmCourse::addCourseInfo($data, $id, Admin::user()->id);
            if ($result) {
                $url = $id ? url('/admin/course/index/') . '/' . $id . '/edit' : url('/admin/course/create');
                return redirect($url)->with(compact('success'));
            } else {
                $error = new MessageBag([
                    'title' => '操作失败'
                ]);
                return back()->withInput()->with(compact('error'));
            }
        } catch (\Exception $e) {
            Log::debug($e->getMessage(), $e->getFile(), $e->getLine());
            $error = new MessageBag([
                'title' => '操作失败,信息:' . $e->getMessage()
            ]);
            return back()->withInput()->with(compact('error'));
        }
    }

    public function createChapter(Request $request, Content $content, $courseId, $chapterId = 0)
    {
        $form = $this->chapterForm($courseId, $chapterId);
        return $content->header('编辑课程章节')->breadcrumb(
            ['text' => '课程信息', 'url' => url('admin/course/index') . '/' . $courseId . '/edit'],
            ['text' => '编辑课程章节'])
            ->row($form);
    }

    public function saveChapter(Request $request)
    {
        try {
            $params = $request->all();
            $courseId = isset($params['course_id']) ? $params['course_id'] : 0;
            if (!$courseId) {
                throw new \Exception('请选择一个课程');
            }
            $id = isset($params['id']) ? $params['id'] : 0;
            $data = [
                'course_id' => $courseId,
                'name' => $params['name'],
                'video_id' => (isset($params['video_id']) && $params['video_id']) ? $params['video_id'] : '',
                'sort' => (isset($params['sort']) && $params['sort']) ? $params['sort'] : 0,
                'is_try' => (isset($params['is_try']) && $params['is_try']) ? $params['is_try'] : 0,
            ];
            if (empty($data['name'])) {
                throw new \Exception('必须设置章节标题');
            }
            if (empty($data['video_id'])) {
                throw new \Exception('必须上传章节视频');
            }
            $result = AdmCourse::addChapter($data, $id, Admin::user()->id);
            if ($result) {
                $url = $courseId ? url('/admin/course/index/') . '/' . $courseId . '/edit' : url('/admin/course/create');
                $url .= '?tab=1';
                return redirect($url)->with(compact('success'));
            } else {
                $error = new MessageBag([
                    'title' => '操作失败'
                ]);
                return back()->withInput()->with(compact('error'));
            }
        } catch (\Exception $e) {
            Log::debug($e->getMessage(), $e->getFile(), $e->getLine());
            $error = new MessageBag([
                'title' => '操作失败,信息:' . $e->getMessage()
            ]);
            return back()->withInput()->with(compact('error'));
        }
    }

    public function white(Request $request, Content $content, $id)
    {
        $uids = WhiteUser::getWhiteUsers($id);
        $uids = $uids ? implode(',', $uids) : '';
        $info = $uids ? ['uids' => $uids] : [];
        $form = new Form($info);
        $form->textarea('uids', '白名单uid')->help('英文逗号隔开');
        $form->action(url('admin/course/') . '/index/' . $id . '/saveWhite');
        return $content->header('课程白名单')->breadcrumb(
            ['text' => '课程信息', 'url' => url('admin/course/index')],
            ['text' => '编辑课程章节'])->row($form->render());
    }


    public function saveWhite(Request $request, $id)
    {
        try {
            $uids = $request->input('uids', '');
            $uids = str_replace('，', ',', trim($uids));
            $uids = explode(',', $uids);
            if ($id) {
                WhiteUser::setWhiteUsers($id, $uids);
                return redirect(url('/admin/course/index/'))->with(compact('success'));
            } else {
                $error = new MessageBag([
                    'title' => '操作失败'
                ]);
                return back()->withInput()->with(compact('error'));
            }
        } catch (\Exception $e) {
            Log::debug($e->getMessage(), $e->getFile(), $e->getLine());
            $error = new MessageBag([
                'title' => '操作失败,信息:' . $e->getMessage()
            ]);
            return back()->withInput()->with(compact('error'));
        }
    }


    public function _index_condition($request)
    {
        $response = [];
        if (isset($request['course_id']) && ($request['course_id'] > 0)) {
            $response['course_id'] = $request['course_id'];
            return $response;
        }
        if (isset($request['title']) && strlen($request['title']) > 0) {
            $response['title[~]'] = $request['title'];
        }
        if (isset($request['course_status']) && strlen($request['course_status']) > 0) {
            $response['course_status'] = $request['course_status'];
        }
        return $response;
    }

}